$(document).ready(
    function(){
        
        var UI = {};
        (function (UI) {
            
            UI.start = function(){
                
                var searchParam = window.location.href.split("#user=")[1];
                var userid = "";
                if(searchParam){
                    userid = searchParam.split("=")[0];
                    
                    //window.location.href = "#";
                }
                
                var args = {
                    action: "Select",
                    userid: userid
                };
                
                $.when(Actions.getUserProfile(args), Actions.getUserRankings(args)).then(
                    function(returnItems, rankings){
                        console.log(returnItems);
                        
                        for(rank in rankings){
                            var rank = rankings[rank];
                            $("#user-rank-" + rank.user_ranking_id).html(rank.description);
                        }
                        
                        //if(returnItems.image !== "") $("#fav-bar-area").css("background", "url(data:" + returnItems.image_type + ";base64," + returnItems.image + ") top center no-repeat").css("background-size", "30% 100%");
                        $("#username").html(returnItems.first_name + " " + returnItems.last_name);
                        $("#user-rank-" + returnItems.user_ranking_id).addClass("rank-active");
                    }
                );
            };
            
        }(UI));
        var Helpers = {};
        (function (Helpers) {
            
            
            
        }(Helpers));
        
        var Actions = {};
        (function (Actions) {
            
            Actions.getUserRankings = function(args) {
                var dfd = new $.Deferred();
                $.ajax({
                    type: "GET",
                    url: "../resources/helpers/getUserRankings.php",
                    data: args,
                    cache: false,
                    success: function(data){
                        data = JSON.parse(data);
                        dfd.resolve(data);
                    }
                });
                return dfd.promise();
            };
            
            Actions.getUserProfile = function(args) {
                var dfd = new $.Deferred();
                $.ajax({
                    type: "GET",
                    url: "../resources/helpers/getUserProfile.php",
                    data: args,
                    cache: false,
                    success: function(data){
                        data = JSON.parse(data);
                        dfd.resolve(data);
                    }
                });
                return dfd.promise();
            };
            
        }(Actions));
        
        var Controller = {};
        (function (Controller) {
            
            Controller.init= function(){
                
            };
            
        }(Controller));	
        
        UI.start();
        Controller.init();
    }
);